<template>
  <div class="container">
    <el-form label-width="100px" :inline="false" v-if="comp">
      <el-form-item label="名称">
        <el-input v-model="comp.name"></el-input>
      </el-form-item>
      <el-form-item label="简称">
        <el-input v-model="comp.shortName"></el-input>
      </el-form-item>
      <el-form-item label="法人">
        <el-input v-model="comp.fr"></el-input>
      </el-form-item>
      <el-form-item label="实际负责人">
        <el-input v-model="comp.sjfzr"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">修改</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import useComp from '@renderer/composables/useComp'
import { ElMessage } from 'element-plus'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const { find, update, comp } = useComp()

find(+route.params.id)
const onSubmit = async () => {
  await update(+route.params.id, {
    name: comp.value?.name,
    shortName: comp.value?.shortName,
    fr: comp.value?.fr,
    sjfzr: comp.value?.sjfzr,
  })
  ElMessage({
    type: 'success',
    message: '修改成功',
  })
  router.push({ name: 'comp.list' })
}
const cancel = async () => {
  router.push({ name: 'comp.list' })
}
</script>

<style lang="scss" scoped>
.container {
  @apply px-5;
}
</style>
